package com.cloud.tsp.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cloud.api.domain.stats.QueryRecord;
import com.cloud.api.domain.stats.RecordList;
import com.cloud.api.domain.tsp.VehicleLogout;
import com.cloud.core.exception.MyException;
import com.cloud.mybatis.domain.TableDataInfo;
import com.cloud.tsp.mapper.VehicleLogoutMapper;
import com.cloud.tsp.service.IVehicleLogoutService;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;

import java.util.Optional;

/**
 * <p>
 * OLAP 服务实现类
 * </p>
 *
 * @author haohaibo
 * @since 2023-12-01
 */
@Service("vehicleLogoutService")
public class VehicleLogoutServiceImpl extends ServiceImpl<VehicleLogoutMapper, VehicleLogout> implements IVehicleLogoutService {

    @Resource
    private VehicleLogoutMapper vehicleLogoutMapper;

    @Override
    public TableDataInfo<RecordList> selectLogoutRecord(QueryRecord para) {
        Page<RecordList> page = new Page<>();
        page.setCurrent(para.getPage());
        page.setSize(para.getPageSize());
        IPage<RecordList> data = vehicleLogoutMapper.selectLogoutRecord(page, para);
        return TableDataInfo.build(data);
    }

    @Override
    public VehicleLogout selectLogoutRecordDetail(QueryRecord para) {
        VehicleLogout vehicleLogout = vehicleLogoutMapper.selectLogoutRecordDetail(para);
        Optional.ofNullable(vehicleLogout).orElseThrow(() -> new MyException("wds.exception.id"));
        vehicleLogout.setRecordLength(vehicleLogout.getRecord().length());
        vehicleLogout.setRecord(vehicleLogout.getRecord().toUpperCase());
        return vehicleLogout;
    }
}